<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: order_details_cart.php 472 2014-01-30 15:59:46Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 472 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-30 15:59:46 +0000 (Thu, 30 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty();
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

require_once (DIR_FS_INC.'inc.check_stock.php');
require_once (DIR_FS_INC.'inc.get_products_stock.php');
require_once (DIR_FS_INC.'inc.remove_non_numeric.php');
require_once (DIR_FS_INC.'inc.get_attributes_model.php');
require_once (DIR_FS_INC.'inc.get_clean_id.php');
require_once (DIR_FS_INC.'inc.get_product_id.php');
require_once (DIR_FS_INC.'inc.get_product_link.php');
require_once (DIR_FS_INC.'inc.decode_urlsearch.php');
require_once (DIR_FS_INC.'inc.parse_product_options.php');
require_once (DIR_FS_INC.'inc.get_shippingtime_functions.php');

$module_content = array();
$any_out_of_stock = '';
$mark_stock = '';
$t_price = '';
$p_price ='';
$max_shipping_time_ranking = 0;

for ($i = 0, $n = sizeof($products); $i < $n; $i ++) {
	if (STOCK_CHECK == 'true') {
		$mark_stock = check_stock($products[$i]['id'], $products[$i]['quantity']);
		if ($mark_stock)
			$_SESSION['any_out_of_stock'] = 1;
	}
	$max_shipping_time_ranking = max($max_shipping_time_ranking, get_shippingtime_rank('name', $products[$i]['shipping_time']));

	$attributes_exist = ( (isset($products[$i]['attributes']) && count($products[$i]['attributes']) > 0) ? true : false);
	$options_exist = ( (isset($products[$i]['options']) && count($products[$i]['options']) > 0) ? true : false);

	$p_price = $products[$i][($attributes_exist||$options_exist ? 'price' : 'single_price')];
	$t_price = $price->format( $p_price * $products[$i]['quantity'], true );
	$p_price = $price->format( $p_price, true );
	$parameter_link = '';
	$product_link = href_link(FILENAME_PRODUCT_INFO, get_all_get_params().'products_id='.get_product_id($products[$i]['id']));

	if ($products[$i]['id']!=get_product_id($products[$i]['id'])) {
		$parameter_link = decode_urlsearch(substr($products[$i]['id'], strlen(get_product_id($products[$i]['id']))));
		$product_link = get_product_link(get_product_id($products[$i]['id']), 'konfigurator').'?p='.$parameter_link;
	}
	
/*	if($attributes_exist)
		$t_price = $price->format(($products[$i]['single_price']*$products[$i]['quantity'])+($_SESSION['cart']->attributes_price($products[$i]['id'])*$products[$i]['quantity']), true);
*/	
	$module_content[$i] = array(
		'PRODUCTS_NAME' => $products[$i]['name'].$mark_stock,
		'PRODUCTS_ID' => $products[$i]['id'],
		'PRODUCTS_ID_CLEAN' => get_clean_id($products[$i]['id']),
		'PRODUCTS_QTY' => draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="3" id="qty_'.$products[$i]['id'].'" class="products_qty"')
										. draw_hidden_field('products_id[]', get_product_id($products[$i]['id']) . ($parameter_link!=''?'{p='.$parameter_link.'}':''))
										. draw_hidden_field('old_qty[]', $products[$i]['quantity']),
		'QTY' => $products[$i]['quantity'],
		'PRODUCTS_MODEL' => $products[$i]['model'],
		'PRODUCTS_NAME_SUFFIX' => $products[$i]['name_suffix'],
		'PRODUCTS_DESCRIPTION' => $products[$i]['desc'],
		'PRODUCTS_SHIPPING_TIME' => (ACTIVATE_SHIPPING_STATUS == 'true' ? $products[$i]['shipping_time']:''),
		'PRODUCTS_TAX' => number_format($products[$i]['tax_class_id'], TAX_DECIMAL_PLACES),
		'PRODUCTS_IMAGE' => $products[$i]['image'],
		'IMAGE_ALT' => $products[$i]['name'],
		'DEL_LINK' => href_link(FILENAME_SHOPPING_CART, get_all_get_params().'del='.$products[$i]['id']),
		'EDIT_LINK' => href_link(FILENAME_PRODUCT_INFO, get_all_get_params().'products_id='.get_product_id($products[$i]['id'])).'?edit='.$products[$i]['id'],
		'DUPL_LINK' => href_link(FILENAME_PRODUCT_INFO, get_all_get_params().'products_id='.get_product_id($products[$i]['id'])).'?dupl='.$products[$i]['id'],
		'PLUS_LINK' => href_link(FILENAME_SHOPPING_CART, get_all_get_params().'plus='.$products[$i]['id']),
		'MINUS_LINK' => href_link(FILENAME_SHOPPING_CART, get_all_get_params().'minus='.$products[$i]['id']),
		'PRODUCTS_LINK' => $product_link,
		'PARAMETER_LINK' => $parameter_link,
		'PRODUCTS_SINGLE_PRICE' => $price->format($products[$i]['single_price'], true),
		'PRODUCTS_PRICE' => $p_price,
		'PRODUCTS_PRICE_TOTAL' => $t_price,
		'ATTRIBUTES' => '',
		'OPTIONS' => '');
								
	if ($options_exist) {
    if ( ($konfigurator = $_SESSION['cart']->use_konfigurator(true, get_prid($products[$i]['id']))) !== false ) {
      $module_content[$i]['OPTIONS'] = array(
        'DESCRIPTION' => $konfigurator->get_description($products[$i]['options'])
      );
    }
  }

	if ($attributes_exist == 1) {
		$count_attr_value = '';
		$count_attr = '';
		$ii = 0;
		$a_price = '';
		reset($products[$i]['attributes']);
		while (list ($option, $value) = each($products[$i]['attributes'])) { $ii++;
  			if (ATTRIBUTE_STOCK_CHECK == 'true' && STOCK_CHECK == 'true') {
  				$attribute_stock_check = check_stock_attributes($products[$i][$option]['products_attributes_id'], $products[$i]['quantity']);
  				if ($attribute_stock_check)
  					$_SESSION['any_out_of_stock'] = 1;
  			}
  			
  			if($products[$i][$option]['products_options_name'] != 'Downloads') {
  				$a_s_price = $price->format($products[$i][$option]['options_values_price'], true, $products[$i]['tax_class_id']);
  				$a_price = $price->format($products[$i][$option]['options_values_price'] * $products[$i]['quantity'], true, $products[$i]['tax_class_id']);
  			}
  				
  			
  			$module_content[$i]['ATTRIBUTES'][] = array('ID' => $products[$i][$option]['products_attributes_id'],
  														'MODEL' => get_attributes_model(get_prid($products[$i]['id']), $products[$i][$option]['products_options_values_name'],$products[$i][$option]['products_options_name']),
  														'NAME' => $products[$i][$option]['products_options_name'],
  														'ATTR_QTY' => ($products[$i][$option]['products_options_name'] != 'Downloads')? $products[$i]['quantity'].'x':'',
  														'PRICE' => $a_price,
  														'SINGLE_PRICE' => $a_s_price,
  														'MODEL' => $products[$i][$option]['products_attributes_model'],
  														'ATTR_ID' => get_prid($products[$i]['id']).'_'.$option.'_'.$value,
  														'PREFIX' =>  ($products[$i][$option]['products_options_name'] != 'Downloads')?$products[$i][$option]['price_prefix']:'',
  														'VALUE_NAME' => $products[$i][$option]['products_options_values_name'].$attribute_stock_check);
  			$count_attr_value += $products[$i][$option]['options_values_price'];
  			$count_attr = $ii;
  		}
		$module_content[$i]['PRODUCTS_ATTR_COUNT'] = $count_attr+2;
	}
}

require(DIR_WS_CLASSES.'class.order_total.php');
$order_total_modules = new order_total();
$order_total_modules->values_from_cart = true;
$total_content_array = $order_total_modules->process(array('ot_subtotal', 'ot_tax', 'ot_total'));

if($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1'
  && $_SESSION['customers_status']['customers_status_ot_discount'] != '0.00') {
	if($_SESSION['customers_status']['customers_status_show_price_tax'] == 0
    && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1)
		$Dprice = $total_content_array['all']['netto'];
	else
		$Dprice = $total_content_array['all']['brutto'];

	$discount = $price->GetDiscount($Dprice, $_SESSION['customers_status']['customers_status_ot_discount']);
	$total_content = '<div class="ot_discount">'.$_SESSION['customers_status']['customers_status_ot_discount'].'% '.SUB_TITLE_OT_DISCOUNT.' -'.format_price($discount, true).'</div>';
}

if($_SESSION['customers_status']['customers_status_show_price'] == '1') {
  $total-=$discount;
	$total_content .= '<div class="ot_subtotal">'.$total_content_array['ot_subtotal']['title'].' <span id="totalcost_ot_subtotal">'.$total_content_array['ot_subtotal']['text'].'</span></div>';

  if(MODULE_SMALL_BUSINESS_STATUS == 'true')
		$total_content .= '<div class="ot_small_business">'.USE_SMALL_BUSINESS_TEXT.'<br />';
  else if ($_SESSION['customers_status']['customers_status_show_price_tax'] != 0 )
		$module_smarty->assign('TOTAL_CONTENT_NETTO', '<div class="ot_total_netto">Netto: '.'<span id="totalcost_ot_total_netto">'.$price->format($total_content_array['all']['netto'], true).'</span></div>');

} else
	$total_content .= '<div class="ot_subtotal">'.NOT_ALLOWED_TO_SEE_PRICES.'</div>';

if ($customer_status_value['customers_status_ot_discount'] != 0)
	$total_content .= TEXT_CART_OT_DISCOUNT.$customer_status_value['customers_status_ot_discount'].'%';

if ($_SESSION['customers_status']['customers_status_show_price'] == '1'
  && MODULE_SMALL_BUSINESS_STATUS != 'true') {
    $total_content_tax = '';
    foreach($total_content_array as $k => $content) {
      if ($content['code'] == 'ot_tax')
        $total_content_tax .= '<div class="ot_tax">'.$content['title'].' <span id="totalcost_'.$k.'">'.$content['text'].'</span></div>';
     	$module_smarty->assign('UST_CONTENT', $total_content_tax);
    }
}

if(SHOW_SHIPPING == 'true')
	$module_smarty->assign('SHIPPING_INFO', $main->getShippingLink());

if(SHOW_SHIPPING_PREVIEW == 'true')
	include(DIR_WS_MODULES.'order_details_shipping_preview.php');

if(CROSSSELLING_CART == 'true' && sizeof($products) > 0)
	include(DIR_WS_MODULES.'order_details_crossselling.php');

$module_smarty->assign('TOTAL_CONTENT', $total_content);
$module_smarty->assign('language', $_SESSION['language']);
$module_smarty->assign('module_content', $module_content);
$module_smarty->caching = false;
$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/order_details.html');

$smarty->assign('MODULE_order_details', $module);